/*
 * Translator.cpp
 *
 *  Created on: Nov 4, 2011
 *      Author: gonzalo
 */

#include "Translator.h"
#include "../DTOCliente.h"
#include "../DTOEvent.h"
#include "../../SDLtoolkit/widgets/SurfaceFactory.h"


Event* Translator::translate(DTOEvent* dto){
	return new Event(dto);
}


Event* Translator::translate(DTOCliente* dto){
	SDL_Event* event = new SDL_Event;
	event->type = UserEvent;
	event->user.code = EXIT;
	return new Event(event);
}


DTO* Translator::translate(Event* event) {

	switch (event->getType()) {
	case KeyPressed:
		return event->transformInDTO();
		break;
	case KeyReleased:
		return event->transformInDTO();
		break;
	case Quit:
		return new DTOCliente(event->getSender(),event->getSender(),DISCONECTED);
	default:
		return NULL;
		break;
	}

	return NULL;

}

std::list<ScenarioElement*> Translator::translateScenarioElementDTO(
		std::list<DTOScenarioElement*> elements) {
	std::list<ScenarioElement*> retorno;

	std::list<DTOScenarioElement*>::iterator it;
	for (it = elements.begin(); it != elements.end(); ++it) {
		DTOScenarioElement* dto = (DTOScenarioElement*) (*it);
		retorno.push_back(new ScenarioElement(dto,SurfaceFactory::getSurface(dto->getElementImagePath())));
	}

	return retorno;
}
